package com.atguigu.c_designed.m1createModel.c2factory.f3abstract;
/**
 * 组成部分
 * 1。抽象工厂角色
 * 2. 具体工厂角色
 * 3. 抽象产品角色
 * 4。 具体产品角色
 */
//抽象产品角色
public abstract class Car {
    abstract void run();
}

// 具体产品角色
class BenzCar extends Car{
    @Override
    void run() {
        System.out.println("running Benz");
    }
}

// 具体产品角色
class BmwCar extends Car{
    @Override
    void run() {
        System.out.println("running Bmw");
    }
}

// 具体产品角色
class AudiCar extends Car{
    @Override
    void run() {
        System.out.println("running Audi");
    }
}

// 抽象工厂角色
abstract class DriverFactory{
    abstract Car getCar();
}

class BenzDriver extends DriverFactory{
    @Override
    public Car getCar(){
        return new BenzCar();
    }
}

class BmwDriver extends DriverFactory{
    @Override
    public Car getCar(){
        return new BmwCar();
    }
}

class AudiDriver extends DriverFactory{
    @Override
    public Car getCar(){
        return new AudiCar();
    }
}
// 司机生产工厂类
class FactoryDriver{
    DriverFactory driverFactory;

    public FactoryDriver(DriverFactory driverFactory) {
        this.driverFactory = driverFactory;
    }

    public void setDriverFactory(DriverFactory driverFactory) {
        this.driverFactory = driverFactory;
    }

    Car getDriver(){
       return driverFactory.getCar();
    }
}

/**
 * 暴发户类
 */
class Mangate{
    public static void main(String[] args) {
        DriverFactory driver = new AudiDriver();
        FactoryDriver factoryDriver = new FactoryDriver(driver);
        //指定要坐什么车
        // 取车
        factoryDriver.getDriver().run();

    }
}